import { del, get, post, put } from "../../../utils/request";
import {
  type AddElderlyFilesParams,
  type AddParams,
  type AddScheduleParams,
  type AddTaskList,
  type AddTaskParams,
  type AddTaskResult,
  type DiseaseResult,
  type ListData,
  type ListElderlyFilesRes,
  type ListParams,
  type ListResult,
  type ScheduleData,
  type ScheduleResult,
} from "./type";
import { type AxiosRequestConfig } from "axios";

export const getElderlyList = (data: ListParams) => {
  return get<ListParams, ListResult>("/api/elderly/list", data);
};

//获取单条
export const getElderlyModel = (id: number) => {
  return get<number, ListData>(`/api/elderly/get/${id}`);
};

//添加
export const addElderly = (data: AddParams) => {
  return post<AddParams, ListData>("/api/elderly/add", data);
};

//修改
export const updateElderly = (data: AddParams) => {
  return put<AddParams, ListData>("/api/elderly/update", data);
};

//删除老人
export const delElderly = (id: number) => {
  return del<null, null>(`/api/elderly/delete/${id}`);
};

//批量删除老人
export const delElderlyMany = (ids: number[]) => {
  return post<number[], null>("/api/elderly/deleteAll", ids);
};

//所有疾病列表
export const getDiseaseList = () => {
  return get<null, DiseaseResult>("/api/disease/list");
};

//自理项目列表
export const getSelfcareList = () => {
  return get<null, DiseaseResult>("/api/selfcare/list");
};

//体检项目列表
export const getCheckupitems = () => {
  return get<null, DiseaseResult>("/api/checkupitems/list");
};

//档案文件
export const getFileitems = () => {
  return get<null, DiseaseResult>("/api/fileitems/list");
};

//添加档案
export const addElderlyFiles = (data: AddElderlyFilesParams) => {
  return post<AddElderlyFilesParams, AddElderlyFilesParams>("/api/elderlyFiles/add", data);
};

//档案列表
export const getElderlyFilesList = (id: number) => {
  return get<number, ListElderlyFilesRes>(`/api/elderlyFiles/list/${id}`);
};

//删除老人档案信息
export const delElderlyFiles = (id: number, fIndex: number) => {
  return del<null, null>(`/api/elderlyFiles/delete/${id}/${fIndex}`);
};

//老人档案下载
export const downFile = (fileName: string) => {
  let config: AxiosRequestConfig = {
    responseType: "blob",
  };
  return post<Record<string, string>, Blob>("/api/elderlyFiles/downloadFile", { fileName }, config);
};

//排班列表
export const getScheduleList = (id: number) => {
  return get<number, ScheduleResult>(`/api/schedule/list/${id}`);
};

//排班添加
export const addSchedule = (data: AddScheduleParams) => {
  return post<AddScheduleParams, ScheduleData>("/api/schedule/add", data);
};

//排班删除
export const delSchedule = (id: number) => {
  return del<number, null>(`/api/schedule/delete/${id}`);
};

//老人任务列表
export const getTaskList = (id: number) => {
  return get<null, AddTaskResult>(`/api/elderlyTask/getTask/${id}`);
};

//任务添加
export const addTask = (data: AddTaskParams) => {
  return post<AddTaskParams, AddTaskList>("/api/elderlyTask/add", data);
};
